package com.bobi.tfca.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bobi.tfca.model.entity.MessageEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 消息持久层
 * @author 李文发
 * @date 2024/4/3
 */
@Mapper
public interface MessageDao extends BaseMapper<MessageEntity> {

    @Update("UPDATE `group_message` " +
            "SET unread_members = REPLACE(unread_members, '{${memberId}}', '')" +
            "WHERE FIND_IN_SET('{${memberId}}', unread_members) > 0 AND group_id = #{groupId};")
    void updateMemberURMsg2Read(@Param("groupId") Integer groupId, @Param("memberId") Integer memberId);

    @Update("UPDATE group_message SET unread_members = REPLACE(unread_members, '{${memberId}}', '') WHERE message_id = #{messageId}")
    void updateGroupMessageRead(@Param("messageId") Long messageId, @Param("memberId") Integer memberId);

    // @Select("SELECT message_id, sender_id, receiver_id, content_type, content_id, category, message_status, send_time FROM message WHERE (message_id, content_id) IN (SELECT MIN(message_id), content_id FROM message GROUP BY content_id) AND sender_id = #{senderId} AND category = #{category}")
    // List<MessageEntity> getSendNotifications(Integer senderId, Integer category);
}
